package cn.jiyun.controller;

import cn.jiyun.entity.CourseDto;
import cn.jiyun.entity.CourseDto2;
import cn.jiyun.entity.day05.CompentDto;
import cn.jiyun.entity.day08.TrainDto;
import cn.jiyun.entity.day09.SjDto;
import cn.jiyun.entity.day09.SjDto2;
import cn.jiyun.entity.day09.SjDto3;
import cn.jiyun.feign.*;
import cn.jiyun.utils.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: CourseController
 * @Author 王鸽
 * @Date 2023/8/23 19:38
 */
@RestController
@RequestMapping("/kc")
public class CourseController {
    @Autowired
    private CourseFegin CourseFegin;
    @Autowired
    private CompentFeign compentFeign;
    @Autowired
    private TrainFegin trainFegin;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private TestParperFeign testParperFeign;
    @Autowired
    private TallyFegin tallyFegin;
    @Autowired
    private DirectoryFegin directoryFegin;
    @RequestMapping("/findCourseNum")
    public ResultResponse findCourseNum() {
        ResultResponse courseNum = CourseFegin.findCourseNum();
        return ResultResponse.success(courseNum);
    }
    @RequestMapping("/findCompentNum")
    public ResultResponse findCompentNum(){
        ResultResponse courseNum = compentFeign.findCompentNum();
        return ResultResponse.success(courseNum);
    }
    @RequestMapping("/findTrainNum")
    public ResultResponse findTrainNum(){
        ResultResponse trainNum = trainFegin.findTrainNum();
        return ResultResponse.success(trainNum);
    }
    @RequestMapping("/findcourse")
    public ResultResponse findcourse() {
        ResultResponse course = CourseFegin.findCourse();
        return ResultResponse.success(course);
    }
    @RequestMapping("/dianzan1")
    public ResultResponse dainzan1(String kcname1){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname1);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname1,1);
        }else {
            redisTemplate.opsForValue().set(kcname1,kcname+1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/dianzan2")
    public ResultResponse dainzan2(String kcname2){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname2);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname2,1);
        }else {
            redisTemplate.opsForValue().set(kcname2,kcname+1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/dianzan3")
    public ResultResponse dainzan3(String kcname3){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname3);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname3,1);
        }else {
            redisTemplate.opsForValue().set(kcname3,kcname+1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/dianzan4")
    public ResultResponse dainzan4(String kcname4){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname4);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname4,1);
        }else {
            redisTemplate.opsForValue().set(kcname4,kcname+1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/find1")
    public ResultResponse find1(String kcname1){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname1);
        return ResultResponse.success(kcname);
    }
    @RequestMapping("/find2")
    public ResultResponse find2(String kcname2){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname2);
        return ResultResponse.success(kcname);
    }
    @RequestMapping("/find3")
    public ResultResponse find3(String kcname3){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname3);
        return ResultResponse.success(kcname);
    }
    @RequestMapping("/find4")
    public ResultResponse find4(String kcname4){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname4);
        return ResultResponse.success(kcname);
    }
    @RequestMapping("/findTrain")
    public ResultResponse findTrain() {
        ResultResponse train = trainFegin.findTrain();
        return ResultResponse.success(train);
    }
    @RequestMapping("/findAlltestparper")
    public ResultResponse findAlltestparper(){
        ResultResponse alltestparper = testParperFeign.findAlltestparper();
        return ResultResponse.success(alltestparper);
    }
    @RequestMapping("/findKcNum1")
    public ResultResponse findKcNum() {
        ResultResponse kcnum = trainFegin.findKcnum();
        return ResultResponse.success(kcnum);
    }
    @RequestMapping("/findTestNum1")
    public ResultResponse findTestNum(){
        ResultResponse testnum = trainFegin.findTestnum();
        return ResultResponse.success(testnum);
    }
    @RequestMapping("/findUser")
    public ResultResponse findUser(){
        ResultResponse user1 = trainFegin.findtestUser();
        return ResultResponse.success(user1);
    }
    @RequestMapping("/findti")
    public ResultResponse findti(){
        ResultResponse findti = testParperFeign.findti();
        return ResultResponse.success(findti);
    }
    @RequestMapping("/findpnum")
    public ResultResponse findpnum() {
        ResultResponse findpnum = CourseFegin.findpnum();
        return ResultResponse.success(findpnum);
    }
    @RequestMapping("/jianzan")
    public ResultResponse jianzan(String kcname1){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname1);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname1,1);
        }else {
            redisTemplate.opsForValue().set(kcname1,kcname-1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/jianzan2")
    public ResultResponse jianzan2(String kcname2){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname2);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname2,1);
        }else {
            redisTemplate.opsForValue().set(kcname2,kcname-1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/jianzan3")
    public ResultResponse jianzan3(String kcname3){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname3);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname3,1);
        }else {
            redisTemplate.opsForValue().set(kcname3,kcname-1);
        }
        return ResultResponse.success(true);
    }
    @RequestMapping("/jianzan4")
    public ResultResponse jianzan4(String kcname4){
        Integer kcname = (Integer) redisTemplate.opsForValue().get(kcname4);
        if (kcname==null){
            redisTemplate.opsForValue().set(kcname4,1);
        }else {
            redisTemplate.opsForValue().set(kcname4,kcname-1);
        }
        return ResultResponse.success(true);
    }
    @GetMapping("/dianzan")
    public ResultResponse dianzan(String name){
        ResultResponse dianzan = CourseFegin.dianzan(name);
        return ResultResponse.success(dianzan);
    }
  @GetMapping("/jianzan")
    public ResultResponse jian(String name){
      ResultResponse jian = CourseFegin.jianzan(name);
      return ResultResponse.success(jian);
  }
  @PostMapping("/findAll2")
    public ResultResponse findAll2(@RequestBody CourseDto courseDto){
      ResultResponse all2 = CourseFegin.findAll2(courseDto);
      return ResultResponse.success(all2);
  }
    @PostMapping("/findAll3")
    public ResultResponse findAll3(@RequestBody CourseDto2 courseDto2){
        ResultResponse all2 = CourseFegin.findAll3(courseDto2);
        return ResultResponse.success(all2);
    }
    @PostMapping("/findAll4")
    public ResultResponse findAll4(@RequestBody CourseDto2 courseDto2){
        ResultResponse all2 = CourseFegin.findAll4(courseDto2);
        return ResultResponse.success(all2);
    }
    @GetMapping("/findById")
    public ResultResponse findById(String cid){
        ResultResponse byCourseId = directoryFegin.findAll2(cid);
        return ResultResponse.success(byCourseId);
    }
    @GetMapping("/findKc")
    public ResultResponse findAllCourse(Long cid) {
        ResultResponse allKc = CourseFegin.findAllKc(cid);
        return ResultResponse.success(allKc);
    }
    @RequestMapping("/updateStatus")
    public ResultResponse updateStatus(Long id){
        ResultResponse resultResponse = directoryFegin.updateStatus(id);
        return ResultResponse.success(resultResponse);
    }
    @RequestMapping("/findAllCompent")
    public ResultResponse findAllCompent(@RequestBody CompentDto compentDto){
        try {
            ResultResponse all2 = compentFeign.findAll2(compentDto);
            return ResultResponse.success(all2);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.error();
        }
    }
    @RequestMapping("/findCompent")
    public ResultResponse findCompent(Integer id){
        ResultResponse byId = compentFeign.findById(id);
        return ResultResponse.success(byId);
    }
    @RequestMapping("/openbaomimg")
    public ResultResponse openbaomimg(Integer id,Integer tid){
        ResultResponse baoming = compentFeign.baoming(id,tid);
        return ResultResponse.success(baoming);
    }

    @RequestMapping("findUserName")
    public ResultResponse findName(){
        try {
            String  username = (String) redisTemplate.opsForValue().get("username");
            return ResultResponse.success(username);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.error();
        }
    }
    @RequestMapping("/findTestparper")
    public ResultResponse findTestparper(Integer id){
        ResultResponse testparper = testParperFeign.findTestparper(id);
        return ResultResponse.success(testparper);
    }
    @PostMapping("/findSt")
    public ResultResponse findSt(Integer id){
        ResultResponse st = testParperFeign.findSt(id);
        return ResultResponse.success(st);
    }
    @RequestMapping("/findStXx")
    public ResultResponse findStXx(Integer id){
        ResultResponse st = testParperFeign.findStXx(id);
        return ResultResponse.success(st);
    }
    @RequestMapping("/findDtJL")
    public ResultResponse findDtJL(Integer jsId,Integer tid){
        ResultResponse dtJL = testParperFeign.findDtJL(jsId,tid);
        return ResultResponse.success(dtJL);
    }
    @RequestMapping("/findDt")
    public ResultResponse findDt(Integer jsId){
        ResultResponse dt = testParperFeign.findDt(jsId);
        return ResultResponse.success(dt);
    }
    @RequestMapping("/findZdf")
    public ResultResponse  findZdf(Integer jsId){
        ResultResponse zdf = testParperFeign.findZdf(jsId);
        return ResultResponse.success(zdf);
    }
    @RequestMapping("/findPHB")
    public ResultResponse findPHB(Integer jsId){
        ResultResponse PHB = testParperFeign.findPHB(jsId);
        return ResultResponse.success(PHB);
    }
    @RequestMapping("/findAlltrain")
    public ResultResponse findAll2(@RequestBody TrainDto trainDto){
        ResultResponse all2 = trainFegin.findAll2(trainDto);
        return ResultResponse.success(all2);
    }
    @RequestMapping("/findCourseNum2")
    public  ResultResponse findCourseNum2(Integer tid){
        ResultResponse courseNum = trainFegin.findCourseNum(tid);
        return ResultResponse.success(courseNum);
    }
    @RequestMapping("/findTestNum")
    public ResultResponse findTestNum(Integer tid) {
        ResultResponse testNum = trainFegin.findTestNum(tid);
        return ResultResponse.success(testNum);
    }
    @RequestMapping("/findTrain2")
    public ResultResponse findTrain2(Integer id){
        ResultResponse train2 = trainFegin.findTrain2(id);
        return ResultResponse.success(train2);
    }
    @RequestMapping("/findCourse2")
    public ResultResponse findCourse(Integer id){
        ResultResponse course = trainFegin.findCourse(id);
        return ResultResponse.success(course);
    }
    @RequestMapping("/findSj")
    public ResultResponse findSj(Integer id){
        ResultResponse sj2 = trainFegin.findSj2(id);
        return ResultResponse.success(sj2);
    }
    @RequestMapping("/findAllSj")
    public ResultResponse findAllSj(@RequestBody SjDto sjDto){
        ResultResponse allSj = testParperFeign.findAllSj(sjDto);
        return ResultResponse.success(allSj);
    }
    @RequestMapping("/findAllSj2")
    public ResultResponse findAllSj2(@RequestBody SjDto2 sjDto2){
        ResultResponse allSj = testParperFeign.findAllSj2(sjDto2);
        return ResultResponse.success(allSj);
    }
    @RequestMapping("/findAllSj3")
    public ResultResponse findAllSj3(@RequestBody SjDto3 sjDto3){
        ResultResponse allSj = testParperFeign.findAllSj3(sjDto3);
        return ResultResponse.success(allSj);
    }
    @RequestMapping("/findTesenum")
    public ResultResponse findTesenum(){
        ResultResponse testnum = testParperFeign.findTestnum();
        return ResultResponse.success(testnum);
    }
    @RequestMapping("/findCourseAll")
    public ResultResponse findCourseAll(@RequestBody CourseDto courseDto){
        ResultResponse all5 = CourseFegin.findAll5(courseDto);
        return ResultResponse.success(all5);
    }
    @RequestMapping("/findCompentAll")
    public ResultResponse findCompentAll(@RequestBody CompentDto compentDto){
        ResultResponse conpentAll = compentFeign.findConpentAll(compentDto);
        return ResultResponse.success(conpentAll);
    }
    @RequestMapping("/findTrainAll")
    public ResultResponse findTrainAll(@RequestBody TrainDto trainDto){
        ResultResponse trainAll = trainFegin.findTrainAll(trainDto);
        return ResultResponse.success(trainAll);
    }


}
